using System.Text;
using SuperSocketProxy;

namespace SocketPorxyServer;

public sealed class HttpPacketResponse : IPacketResponse
{
    private static readonly ReadOnlyMemory<byte> ConnectSuccess = Encoding.UTF8.GetBytes("HTTP/1.1 200 Connection established\r\n");
    private static readonly ReadOnlyMemory<byte> ProxyAuthentication = Encoding.UTF8.GetBytes("HTTP/1.1 407 Proxy Authentication Required\r\n");
    
    private readonly SocketProxySession _session;

    public HttpPacketResponse(SocketProxySession session)
    {
        _session = session;
    }
    
    ValueTask IPacketResponse.SendHandshakeAsync(bool verifyUser)
    {
        throw new NotImplementedException();
    }

    ValueTask IPacketResponse.SendVerifyAsync(bool verifyResult)
    {
        return _session.SendAsync(ProxyAuthentication);
    }

    ValueTask IPacketResponse.SendConnectAsync(ConnectTargetErrorType connectTargetResult)
    {
        return _session.SendAsync(ProxyAuthentication);
    }
    
    ValueTask IPacketResponse.SendConnectAsync(Socket5EndPointPacket packet)
    {
        throw new NotImplementedException();
    }
    
    ValueTask IPacketResponse.SendConnectHttpAsync()
    {
        return _session.SendAsync(ConnectSuccess);
    }
}